package approve.adapter;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.List;

import model.pojo.Employee;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TableRow;
import android.widget.TextView;
import approve.action.App_ViewForm11;
import approve.action.App_ViewForm12;
import approve.action.App_ViewForm13;
import approve.action.App_ViewForm14;
import approve.action.App_ViewForm15;
import approve.action.App_ViewForm16;
import approve.action.App_ViewForm17;
import approve.action.App_ViewForm_LessThan10;
import approve.action.R;
import approve.model.ListApprove;

public class ListApproveAdapter  extends BaseAdapter{

	private Context context;
	private List<ListApprove> arrayLstApp;
	private Bundle language;
	private Employee employee;
	String database,lang="EN";
	LinearLayout flag = null;
	ViewHolder holder;
	public ListApproveAdapter(Context context,List<ListApprove> arrayLstApp, Bundle language, Employee employee,String database, String lang) {
		super();
		this.context = context;
		this.arrayLstApp = arrayLstApp;
		this.language = language;
		this.employee = employee;
		this.database = database;
		this.lang = lang;
	}
	public ListApproveAdapter(App_ViewForm_LessThan10 context,List<ListApprove> arrayLstApp, Bundle language,
			Employee employee,String database, String lang,int flagForm) {
		super();
		this.context = context;
		this.arrayLstApp = arrayLstApp;
		this.language = language;
		this.employee = employee;
		this.database = database;
		this.lang = lang;
	}
	
	public ListApproveAdapter(App_ViewForm11 context,List<ListApprove> arrayLstApp, Bundle language,
			Employee employee,String database, String lang,int flagForm) {
		super();
		this.context = context;
		this.arrayLstApp = arrayLstApp;
		this.language = language;
		this.employee = employee;
		this.database = database;
		this.lang = lang;
	}
	
	public ListApproveAdapter(App_ViewForm12 context,List<ListApprove> arrayLstApp, Bundle language,
			Employee employee,String database, String lang,int flagForm) {
		super();
		this.context = context;
		this.arrayLstApp = arrayLstApp;
		this.language = language;
		this.employee = employee;
		this.database = database;
		this.lang = lang;
	}
	
	public ListApproveAdapter(App_ViewForm13 context,List<ListApprove> arrayLstApp, Bundle language,
			Employee employee,String database, String lang,int flagForm) {
		super();
		this.context = context;
		this.arrayLstApp = arrayLstApp;
		this.language = language;
		this.employee = employee;
		this.database = database;
		this.lang = lang;
	}
	
	public ListApproveAdapter(App_ViewForm14 context,List<ListApprove> arrayLstApp, Bundle language,
			Employee employee,String database, String lang,int flagForm) {
		super();
		this.context = context;
		this.arrayLstApp = arrayLstApp;
		this.language = language;
		this.employee = employee;
		this.database = database;
		this.lang = lang;
	}
	
	public ListApproveAdapter(App_ViewForm15 context,List<ListApprove> arrayLstApp, Bundle language,
			Employee employee,String database, String lang,int flagForm) {
		super();
		this.context = context;
		this.arrayLstApp = arrayLstApp;
		this.language = language;
		this.employee = employee;
		this.database = database;
		this.lang = lang;
	}
	
	public ListApproveAdapter(App_ViewForm16 context,List<ListApprove> arrayLstApp, Bundle language,
			Employee employee,String database, String lang,int flagForm) {
		super();
		this.context = context;
		this.arrayLstApp = arrayLstApp;
		this.language = language;
		this.employee = employee;
		this.database = database;
		this.lang = lang;
	}
	
	public ListApproveAdapter(App_ViewForm17 context,List<ListApprove> arrayLstApp, Bundle language,
			Employee employee,String database, String lang,int flagForm) {
		super();
		this.context = context;
		this.arrayLstApp = arrayLstApp;
		this.language = language;
		this.employee = employee;
		this.database = database;
		this.lang = lang;
	}

	@Override
	public int getCount() {
		return arrayLstApp.size();
	}

	@Override
	public Object getItem(int arg0) {
		return arrayLstApp.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return 0;
	}

	@Override
	public View getView(int position, View convertview, ViewGroup arg2) {
		ListApprove app = arrayLstApp.get(position);
		
		if(convertview==null){
			holder = new ViewHolder();
			
			LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			convertview=inflater.inflate(R.layout.app_adapter_listapprove, arg2,false);
			
			holder.tvorder=(TextView)convertview.findViewById(R.id.tvorder);
			holder.tvname=(TextView)convertview.findViewById(R.id.tvname);
			holder.tvstatus=(TextView)convertview.findViewById(R.id.tvstatus);
			holder.tvcomment=(TextView)convertview.findViewById(R.id.tvadcomment);
			holder.tvrefer=(TextView)convertview.findViewById(R.id.tvrefer);
			
			holder.tableRowRefer = (TableRow)convertview.findViewById(R.id.tableRowRefer);
			holder.tableRowComment = (TableRow)convertview.findViewById(R.id.tableRowComment);
			holder.valrefer = (TextView)convertview.findViewById(R.id.valrefer);
			holder.valcomment = (TextView)convertview.findViewById(R.id.valcomment);
			
			convertview.setTag(holder);
		}else{
			holder = (ViewHolder)convertview.getTag();
			
		}
		
		holder.tableRowRefer.setVisibility(View.GONE);
		holder.tableRowComment.setVisibility(View.GONE);
		
		holder.tvorder.setText("+"+" "+language.getString("stepapp")+" "+ app.getOrder()+":");
		holder.tvorder.setTextColor(Color.YELLOW);
		holder.tvname.setText(app.getEmname());
		
		DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		
		if(app.getStatusname() != null && (app.getiDStatus() % 2 !=0 )){
			if(app.getDateApprove()!=null){
				holder.tvstatus.setText(" - "+app.getStatusname()+" ( "+ df.format(app.getDateApprove())+")");
			}
		}else if(app.getStatusname()==null){
			holder.tvstatus.setText(" - "+language.getString("empApprove")+" ( "+ df.format(app.getDateApprove())+")");
		}else{
			holder.tvstatus.setText(" - "+app.getStatusname());
		}
		
		
		if(app.getListrefer().equals("")){
			holder.tableRowRefer.setVisibility(View.GONE);
			holder.tvrefer.setText("");				
			holder.valrefer.setText("");
		}else{
			holder.tableRowRefer.setVisibility(View.VISIBLE);
			holder.tvrefer.setText(language.getString("reference")+": ");
			holder.valrefer.setText(app.getListrefer());
		}
		
		if(app.getDescription() != null){
			holder.tableRowComment.setVisibility(View.VISIBLE);
			holder.tvcomment.setText(language.getString("comment")+": ");
			holder.valcomment.setText(app.getDescription());
		}else{
			holder.tableRowComment.setVisibility(View.GONE);
			holder.tvcomment.setText("");
			holder.valcomment.setText("");
		}
		
		return convertview;
	}
	
	

	public Context getContext() {
		return context;
	}

	public void setContext(Context context) {
		this.context = context;
	}

	public List<ListApprove> getArrayLstApp() {
		return arrayLstApp;
	}

	public void setArrayLstApp(List<ListApprove> arrayLstApp) {
		this.arrayLstApp = arrayLstApp;
	}

	public Bundle getLanguage() {
		return language;
	}

	public void setLanguage(Bundle language) {
		this.language = language;
	}

	public Employee getEmployee() {
		return employee;
	}

	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

	public String getDatabase() {
		return database;
	}

	public void setDatabase(String database) {
		this.database = database;
	}

	public String getLang() {
		return lang;
	}

	public void setLang(String lang) {
		this.lang = lang;
	}
	
	public static class ViewHolder{
		TextView tvorder,tvname,tvstatus,tvcomment,tvrefer,valrefer,valcomment;
		TableRow tableRowRefer,tableRowComment;
	}
	
}
